<template>
  <div class="login-container">
    <input type="text" v-model="loginForm.username" />
    <button @click="login">登录</button>
  </div>
</template>
<script setup lang="ts" name="login">
import { useUserStore } from '@/store/modules/user';
import { LoginData, LoginResult } from '@/types/user'
import { reactive } from "vue";
import router from "@/router";

const userStore = useUserStore()


// 登录表单数据
const loginForm = reactive<LoginData>({
  username: ""
});
const login = async () => {
  const res: Result<LoginResult>|null = await userStore.login(loginForm);
  console.log("login vue ", res);
  if (res!=null && res.code === 1000) {
    // 登录成功，跳转hello
    console.log("userStore.token", userStore.token);
    router.push({ path: "/hello" });
  }
};
</script>